# 1. 实现跳跃的效果
# 2. 实现跳跃时帧的切换
import pygame
import player
# 引入pygame中所有常量，比如 QUIT
from pygame.locals import *


# 初始化
pygame.init()
# 设置一个基础的窗口
screen = pygame.display.set_mode((800, 800))
# 背景色为白色
screen.fill((255, 255, 255))

player = player.Player('maliao')
player.rect.x = 0
player.rect.y = 650

# 引入时钟对象
clock = pygame.time.Clock()

# 无限循环，让窗口停留
while True:
    # 退出程序
    for event in pygame.event.get():
        if event.type == QUIT:
            exit()

    if pygame.key.get_pressed():
        player.update(pygame.key.get_pressed())

    # 刷新背景，防止残影
    screen.fill((255, 255, 255))
    # 限制小人不能跑出屏幕外
    if(player.rect.x > 750):
        player.rect.x = 750
    if(player.rect.x < 0):
        player.rect.x = 0
    if(player.rect.y > 750):
        player.rect.y = 750
    if(player.rect.y < 0):
        player.rect.y = 0
    player.draw(screen)
    # 更新屏幕
    pygame.display.flip()
    # 设置帧率为60
    clock.tick(60)
